import java.util.*;

public class comparableTreeSet {
    public static void main(String[] args) {
        TreeSet<Person> people = new TreeSet();
        Person a = new Person("A",10);
        Person b = new Person("B",3);
        Person c = new Person("C",10);
        people.add(a);
        people.add(b);
        people.add(c);
        for (Person p : people){
            System.out.println(p.toString());
        }
        ArrayList f = new ArrayList();
        HashMap N = new HashMap();
        N.put(1,1);
        System.out.println(N.get(1));
        HashSet t = new HashSet();
        t.add(a);
        t.add(b);
        t.add(c);
        for (Object p : t){
            System.out.println(((Person)p));
        }
    }
    public static class Person implements Comparable{
        String name;
        int age;
        public Person(String name,int age){
            this.name=name;
            this.age=age;
        }
        public Person(int na,int age){
            char ch = (char) ((char)na+65);
            this.name=ch+"";
            this.age=age;
        }
        public String toString(){

            return name+":"+age;
        }
        public int hashCode(){
            return name.hashCode()+age;
        }
        public boolean equals(Object o){
            Person p = (Person) o;
            return name.equals(p.name)&&age==p.age;
        }
        public int compareTo(Object o) {
            if (age!=((Person) o).age){
                return age-((Person) o).age;
            }
            else{
                return name.compareTo(((Person)o).name);
            }
        }
    }
}